<!--
* description: 采购管理-欠拨结案规则设置
* author: hzm
* createdDate: 2021-1-22
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="dynamicApiConfigs"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-is-fix-choose="false"
      :dynamic-is-fix-index="false"
      :callback-obj="callbackObj"
      :dynamic-api-style="'restful'"
    />
  </div>
</template>

<script>
import { formMixins } from '@/components/mixins/formMixins'
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import { orgApis } from '@/api/paSparePartsManagement'

export default {
  name: 'SettingClosingRules',
  components: {
    OneTableTemplate
  },
  mixins: [oneTableWithViewTemplateMixins, formMixins],
  data() {
    return {
      dynamicApiConfigs: orgApis.queryUnderdialEndRuleSetInfo,
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'lookupValueName',
              label: '网点类型',
              align: 'center'
            },
            {
              prop: 'attribute1',
              label: '欠拨结案天数',
              align: 'center'
            },
            {
              prop: 'isEnable',
              label: '状态',
              align: 'center'
            },
            {
              prop: 'remark',
              label: '备注',
              align: 'center'
            },
            {
              prop: 'lastUpdatedDate',
              label: '最后修改时间',
              align: 'center'
            },
            {
              prop: 'modifyName',
              label: '最后修改人',
              align: 'center'
            }
          ],
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            // 库存状态
            {
              compKey: 'compKey1',
              labelName: '网点类型：',
              codeField: 'lookupValueName',
              textField: 'lookupValueName',
              customObj: {
                api: orgApis.queryDropDownListAlong
              },
              component: () => import('@/components/org/commonSelect'),
              type: 'dropdownList',
              isMust: true,
              span: 6,
              disabled: true
            },
            // 车辆状态
            {
              compKey: 'compKey2',
              labelName: '欠拨结案时间(天)：',
              codeField: 'attribute1',
              lookuptype: 'VE0207',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              validrule: { isformat: /^[0-9]*[1-9][0-9]*$/, noRequire: false },
              isMust: true,
              span: 6
            },

            // 审核状态
            {
              compKey: 'compKey3',
              labelName: '状态：',
              codeField: 'isEnable',
              textField: 'statusText',
              component: () => import('@/components/org/commonSelect'),
              oFields: 'statusId,statusText',
              options: [
                { statusId: '1', statusText: '是' },
                { statusId: '0', statusText: '否' }
              ],
              type: 'dropdownList',
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey4',
              labelName: '备注：',
              codeField: 'remark',
              lookuptype: 'VE0212',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              span: 6
            }
          ],
      tableButtons: [
        {
          conmpKey: 'btenKey1',
          type: 'primary',
          size: 'small',
          text: '保存',
          name: '',
          clickEvent: () => this.save(),
          position: 'right'
        },
        {
          conmpKey: 'btenKey2',
          type: '',
          size: 'small',
          text: '重置',
          name: 'reset',
          clickEvent: () => this.reset(),
          position: 'right'
        }
      ],
      formField: this.$utils.getFormField(this, {
        lookupValueName: '',
        attribute1: '',
        isEnable: '',
        remark: '',
        uid: ''
      }),
      callbackObj: {
        onRowDbClick: (row, column, event, rowIndex) => {
          for (const key in this.formField) {
            this.formField[key] = row[key]
          }
        }
      }
    }
  },
  mounted() {
    this.queryTable(1)
    // this.$refs.multipleTable.list = [{
    //   index: 1
    // }]
  },
  methods: {
    save() {
      const that = this
      const queryObj = {
        // 保存mutation
        type: 'mutation',
        // api配置
        apiConfig: orgApis.updateLookupValue,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: this.formField
      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD).then(response => {
        if (response.result == 1) {
          this.$message({
            message: '保存成功' /* 保存成功*/,
            type: 'success',
            duration: 1000
          })
          this.reset()
          this.queryTable(1)
        } else {
          // 保存失败
          this.$message({
            message: '保存失败' /* 保存失败*/,
            type: 'error',
            duration: 1000
          })
        }
        this.popupsVisible = false
      })
    }
  }
}
</script>

<style>
</style>
